package org.wenhua.yuan.and.cmbc

import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import android.text.style.TypefaceSpan
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import org.wenhua.androidaar.JHDisplayUtils
import org.wenhua.yuan.R
import org.wenhua.yuan.uilib.UIDataItem

class CMBCFinance2AreaItem(data: List<CMBCDataFinanceArea>) : UIDataItem<List<CMBCDataFinanceArea>, RecyclerView.ViewHolder>(){
    override fun onBindViewHolderInChild(position: Int, viewHolder: RecyclerView.ViewHolder) {

        viewHolder.itemView.findViewById<TextView>(R.id.text1).text = "借款推荐"
        viewHolder.itemView.findViewById<TextView>(R.id.attempt_text1).text = "闪电贷"
        val textMoneyNum = viewHolder.itemView.findViewById<TextView>(R.id.attempt_text3)
        viewHolder.itemView.findViewById<TextView>(R.id.finance_text1).text = "闪电贷招米值"
        viewHolder.itemView.findViewById<TextView>(R.id.finance2_text1).text = "经营贷"
        viewHolder.itemView.findViewById<Button>(R.id.attempt_btn).text = "测一下"

        //创建一个 SpannableString对象
        val moneyNum = "300,000元"
        val len = moneyNum.length - 1
        val msp = SpannableString(moneyNum)
        //设置字体大小（绝对值,单位：像素）
        msp.setSpan(AbsoluteSizeSpan(JHDisplayUtils.dp2px(20f)), 0, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        //设置字体前景色
        msp.setSpan(ForegroundColorSpan(Color.parseColor("#f16160")), 0, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  //设置前景色为洋红色

        textMoneyNum.text = msp


        val textClientNum = viewHolder.itemView.findViewById<TextView>(R.id.attempt_text5)
        //创建一个 SpannableString对象
        val clientNum = "450万人已购买"
        val clientMsp = SpannableString(clientNum)
        //设置字体大小（绝对值,单位：像素）
        clientMsp.setSpan(AbsoluteSizeSpan(JHDisplayUtils.dp2px(16f)), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        //设置字体前景色
        clientMsp.setSpan(ForegroundColorSpan(Color.parseColor("#9e9e9e")), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        textClientNum.text = clientMsp

        val textRateNum2 = viewHolder.itemView.findViewById<TextView>(R.id.finance3_text3)
        //创建一个 SpannableString对象
        val RateNum2 = "成立依赖年化2.76%"
        val RateMsp2 = SpannableString(RateNum2)
        //设置字体大小（绝对值,单位：像素）
        RateMsp2.setSpan(AbsoluteSizeSpan(JHDisplayUtils.dp2px(16f)), 6, RateNum2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        //设置字体前景色
        RateMsp2.setSpan(ForegroundColorSpan(Color.parseColor("#9e9e9e")), 6, RateNum2.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        textRateNum2.text = RateMsp2

        val textRateNum1 = viewHolder.itemView.findViewById<TextView>(R.id.finance_text3)
        //创建一个 SpannableString对象
        val RateNum1 = "业绩比较基准2.70%"
        val RateMsp1 = SpannableString(RateNum1)
        //设置字体大小（绝对值,单位：像素）
        RateMsp1.setSpan(AbsoluteSizeSpan(JHDisplayUtils.dp2px(18f)), 6, RateNum1.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        //设置字体前景色
        RateMsp1.setSpan(ForegroundColorSpan(Color.parseColor("#9e9e9e")), 6, RateNum1.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        textRateNum1.text = RateMsp1

    }

    override fun getItemResource(): Int {
        return R.layout.cmbc_finance_area
    }

}